<template>
  <el-form :model="form" ref="form">
    <el-form-item>
      <el-input v-model="form.username" placeholder="邮箱地址"></el-input>
    </el-form-item>
    <el-form-item>
      <el-input type="password" v-model="form.password" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="parimy" @click="onLogin">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'LoginForm',
  data () {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    onLogin () {
      this.$axios.post('login', this.form).then(resp => {
        if (resp.data.code === 11) {
          this.$message('登录成功')
          this.$store.commit('setToken', resp.data.payload.tokenValue)
          this.$router.replace('/')
        } else {
          this.$message('用户名密码错误')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
